package com.controller;

import com.model.OrderModel;
import com.services.IOrderServices;
import com.services.impl.OrderServicesImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Program: exam
 * @ClassName: ReCarServletController
 * @Description: 处理还车请求
 * @Author: li
 * @Create: 2024-12-23 19:00
 */
@WebServlet("/ReCarServlet")
public class ReCarServletController extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("application/json;charset=utf-8");
        
        try {
            String oid = request.getParameter("oid");
            String cid = request.getParameter("cid");

            OrderModel orderModel = new OrderModel();
            orderModel.setCid(Integer.parseInt(cid));
            orderModel.setOid(Integer.parseInt(oid));
            
            IOrderServices services = new OrderServicesImpl();
            services.successOrder(orderModel);

            // Return success code
            response.getWriter().print("{\"code\":0}");
        } catch (Exception e) {
            // Return error code
            response.getWriter().print("{\"code\":1,\"msg\":\"还车操作失败\"}");
        }
    }
}
